/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.googlecode.asm_ide.project;

import com.googlecode.asm_ide.gui.MainJFrame;
import java.io.File;
import javax.swing.JFileChooser;

/**
 *
 * @author Philipp Hell <philipp@hell.info>
 */
public class NewProjectJDialog extends javax.swing.JDialog {

    /**
     * Creates new form NewProjectJDialog
     */
    public NewProjectJDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        this.parent = (MainJFrame) parent;
        initComponents();
        
        this.backJButton.setEnabled(false);
        this.finishJButton.setEnabled(false);
        this.nextJButton.setEnabled(false); 
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        projectNameJLabel = new javax.swing.JLabel();
        projectPathJLabel = new javax.swing.JLabel();
        changePathJButton = new javax.swing.JButton();
        backJButton = new javax.swing.JButton();
        nextJButton = new javax.swing.JButton();
        cancelJButton = new javax.swing.JButton();
        finishJButton = new javax.swing.JButton();
        projectNameJTextField = new javax.swing.JTextField();
        projectPathJTextField = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("New Project");

        projectNameJLabel.setText("Project name:");

        projectPathJLabel.setText("Project path:");

        changePathJButton.setText("Change");
        changePathJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                changePathJButtonActionPerformed(evt);
            }
        });

        backJButton.setText("Back");
        backJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backJButtonActionPerformed(evt);
            }
        });

        nextJButton.setText("Next");
        nextJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nextJButtonActionPerformed(evt);
            }
        });

        cancelJButton.setText("Cancel");
        cancelJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelJButtonActionPerformed(evt);
            }
        });

        finishJButton.setText("Finish");
        finishJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                finishJButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(backJButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(nextJButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 70, Short.MAX_VALUE)
                .add(finishJButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(cancelJButton))
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(projectNameJLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(projectNameJTextField))
                    .add(layout.createSequentialGroup()
                        .add(projectPathJLabel)
                        .add(12, 12, 12)
                        .add(projectPathJTextField)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(changePathJButton))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(projectNameJLabel)
                    .add(projectNameJTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(projectPathJTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(projectPathJLabel)
                    .add(changePathJButton))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 201, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(backJButton)
                    .add(nextJButton)
                    .add(cancelJButton)
                    .add(finishJButton)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void changePathJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changePathJButtonActionPerformed
        jFileChooser = new JFileChooser();
        jFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        if (jFileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            File f = jFileChooser.getSelectedFile();
            projectPathJTextField.setText(f.getPath());
            finishJButton.setEnabled(true);
        }
    }//GEN-LAST:event_changePathJButtonActionPerformed

    private void finishJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_finishJButtonActionPerformed
        parent.openProject(Project.createProject(projectNameJTextField.getText(), new File(projectPathJTextField.getText())));
        this.dispose();
    }//GEN-LAST:event_finishJButtonActionPerformed

    private void nextJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextJButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_nextJButtonActionPerformed

    private void backJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backJButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_backJButtonActionPerformed

    private void cancelJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelJButtonActionPerformed
        this.dispose();
    }//GEN-LAST:event_cancelJButtonActionPerformed
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton backJButton;
    private javax.swing.JButton cancelJButton;
    private javax.swing.JButton changePathJButton;
    private javax.swing.JButton finishJButton;
    private javax.swing.JButton nextJButton;
    private javax.swing.JLabel projectNameJLabel;
    private javax.swing.JTextField projectNameJTextField;
    private javax.swing.JLabel projectPathJLabel;
    private javax.swing.JTextField projectPathJTextField;
    // End of variables declaration//GEN-END:variables
    private MainJFrame parent;
    private JFileChooser jFileChooser;
}